EDK - Port
----------

A port is a group of eight parallel lines. Up to 16 ports can be connected together. At Init(), the parent object can specify an OnChange function. When the state of the port changes, the OnChange function gets called.

Here is an example how two ports are used to connect a matrix of 8x8 keys to a CIA (the IO chip in a C64):

  class Keyboard : public Object {
    void OnRowChange(byte bNewState, byte bChanges) {
      // add code which ands the matrix rows
      Column.SetPort(bNewColumn);
    }
    void OnColumnChange(byte bNewState, byte bChanges) {
      // add code which ands the matrix columns
      Row.SetPort(bNewRow);
    }
  protected:
    DoInit() {
      Row.Init("Row", this);
      Row.SetOnChange((pfnbb)OnRowChange);
      Column.Init("Column", this);
      Column.SetOnChange((pfnbb)OnColumnChange);
    }
  public:
    Port Row;
    Port Column;
  };

  // excerpt from the emulated computer
  Keyboard keyboard;
  CIA6526 CIA1;
  keyboard.Row.ConnectTo(CIA1.PA);
  keyboard.Column.ConnectTo(CIA1.PB);

When the C64 wants to read the keyboard, it shifts a zero bit through port A of the CIA1. Because keyboard.Row is connected to CIA1.PA, the function OnRowChange() gets called each time when CIA1.PA is changed. OnRowChange() will then scan the keyboard matrix and output the result to keyboard.Column. Because CIA1.PB is connected to keyboard.Column, the C64 will get the new state of the matrix when it reads back port B of the CIA.
